package pers.weiney.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import pers.weiney.annotation.State;

/**
 * @Author: @Weiney
 * @ClassName: StateValidation
 * @Description: 文章的state参数校验
 * @Create: 2024-08-13
 **/

public class StateValidation implements ConstraintValidator<State, String> {

    /**
     * @param value 要校验的数据
     * @param constraintValidatorContext 
     * @return boolean
     * @author @Weiney
     * @description 自定义校验规则
     **/
    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        // 提供校验规则
        if(value == null || value.isEmpty()){
            return false;
        }
        if(value.equals("草稿") || value.equals("已发布")){
            return true;
        }
        return false;
    }
}